﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Tour.BLL;
using Tour.DAL;

public partial class Admin_Modules_Config_ConfigAE : VST.Controls.BaseLCGPage
{
    public int? ConfigId { get; set; }
    protected void Page_Load(object sender, EventArgs e)
    {
        ConfigId = CommonHelper.QueryStringInt("ConfigId", null);
        if (!IsPostBack)
        {
           LoadData();

        }
    }
    void LoadData()
    {
        if (ConfigId.HasValue)
        {
            TblConfigEntity item = TblConfigManager.CreateInstant().SelectOne(ConfigId.Value);
            txtName.Text = item.Title;
            radEditorContent.Content = item.Content;
        }
    }
    TblConfigEntity GetTblConfig()
    {
        TblConfigEntity item = new TblConfigEntity();
        if (ConfigId.HasValue)
        {
            item = TblConfigManager.CreateInstant().SelectOne(ConfigId.Value);
        }
        else
        {
            item.Id = -1;//cai cho nay
            item.Title = txtName.Text;
            item.TextID = TblConfigManager.CreateInstant().GetUniqueTextIdFromUnicodeText(txtName.Text);
            //item.TourId = TourId.Value;
            item.LanguageId = WorkingLanguage;
            item.DisplayOrder = 1;
            item.Content = radEditorContent.Content;
            item.CreatedBy = HttpContext.Current.User.Identity.Name;
            item.CreatedDate = DateTime.Now;
            item.UpdatedBy = HttpContext.Current.User.Identity.Name;
            item.UpdatedDay = DateTime.Now;
        }
        item.Content = radEditorContent.Content;
        return item;
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        TblConfigManager.CreateInstant().InsertUpdate(GetTblConfig());
        Response.Redirect("ConfigList.aspx?ConfigId=" + ConfigId);
    }

}